<html>
    <head>
        <title>Contoh Page</title>
        <style>
            div{margin-bottom:5px}
            .list{margin-left:7px}
            th,td{
                border: black 1px solid;
            }
            td{
                padding: 2px;
                text-align: right;
            }
        </style>
    </head>
    <body>
        <form method="post">
            <div>Bulan (angka): <input type="text" name="month" /></div>
            <div>Tahun (angka): <input type="text" name="year" /></div>
            <div>
                Tipe:
                <select name="type">
                    <option value="s">Sales</option>
                    <option value="p">Payment</option>
                </select>
            </div>
            <div><input type="submit" value="Submit" /></div>
        </form>
        
        <?php if(isset($sales)): ?>
        <div>Sales</div>
        <table>
            <tr>
                <th>Day</th>
                <th>Date</th>
                <th>Beverage</th>
                <th>Food</th>
                <th>Tobaco</th>
                <th>Others</th>
                <th>Discount</th>
                <th>Rounding</th>
                <th>Net Sales</th>
                <th>Tax</th>
                <th>Service</th>
                <th>Subtotal</th>
                <th>Month to Date</th>
            </tr>
            <tr>
            <?php
                $month_to_date = 0; // cumulative subtotal
                foreach($sales as $val): 
            ?>
            <tr>
                <?php $month_to_date += $val['subtotal'] ?>
                <td><?=date("D",strtotime($val['date']))?></td>
                <td><?=$val['date']?></td>
                <td><?=$val['beverage']?></td>
                <td><?=$val['food']?></td>
                <td><?=$val['tobaco']?></td>
                <td><?=$val['others']?></td>
                <td><?=$val['discount']?></td>
                <td><?=$val['rounding']?></td>
                <td><?=$val['net_sales']?></td>
                <td><?=$val['tax']?></td>
                <td><?=$val['service']?></td>
                <td><?=$val['subtotal']?></td>
                <td><?=$month_to_date?></td>
            </tr>
            <?php 
                endforeach; 
            ?>
            </tr>
        </table>
        <?php endif; ?>
        
        <?php if(isset($payment)): ?>
        <div>Payment</div>
        <table>
            <tr>
                <th>DATE</th>
                <th>CASH</th>
                <th>VISA</th>
                <th>MASTER</th>
                <th>BCA CARD</th>
                <th>DEBIT</th>
                <th>CL</th>
                <th>VOUCHER</th>
                <th>TOTAL</th>
                <th>MONTH TO DATE</th>
            </tr>
            <tr>
            <?php
            $month_to_date = 0; // cumulative subtotal
            foreach($payment as $val): 
            ?>
            <tr>
                <?php $month_to_date += $val['total'] ?>
                <td><?=$val['date']?></td>
                <td><?=$val['cash']?></td>
                <td><?=$val['visa']?></td>
                <td><?=$val['master']?></td>
                <td><?=$val['bca_card']?></td>
                <td><?=$val['debit']?></td>
                <td><?=$val['city_ledger']?></td>
                <td><?=$val['voucher']?></td>
                <td><?=$val['total']?></td>
                <td><?=$month_to_date?></td>
            </tr>
            <?php endforeach; ?>
            </tr>
        </table>
        <?php endif; ?>
        
    </body>
</html>